package 每日一题;

import org.junit.Test;

public class 字符串中的单词数 {
    public int countSegments(String s) {
        String trim = s.trim();
        if (trim.equals(""))
            return 0;
        String[] split = trim.split(" ");
        int num=0;
        for (String s1 : split) {
            if (s1.equals(""))
                continue;
            num++;
        }
        return num;
    }
    @Test
    public void test(){
        String s = ", , , ,         a, eaefa";
        System.out.println(countSegments(s));
    }
}
